<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>排序算法</title>
</head>
<body>
    
</body>
<Script>
    var arr=[43,56,16,5,87,37,98,48,39]
    for(var i=0;i<arr.length;i++){
        for(var j=0;j<arr.length-1-i;j++){
            if(arr[j]>arr[j+1]){
                [arr[j],arr[j+1]]=[arr[j+1],arr[j]];
            }
           
        }
    }
    console.log(arr)
    //插入排序
    /* 
     把一个数插入到已经排好序的数组中
    */
    //排序方法arr.sort
    var arr1=[43,56,16,5,87,37,98,48,39];
    arr1.sort(function(a,b){return a-b});
    console.log(arr1);

</Script>
</html>